﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Mvc4Learn.Models;

namespace Mvc4Learn.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.Message = "修改此模板以快速启动你的 ASP.NET MVC 应用程序。";

            return View();
        }

        public ActionResult About()
        {
            ViewBag.Message = "你的应用程序说明页。";

            return View();
        }

        public ActionResult Test(int? id)
        {
            ViewBag.Message = "测试页。";
            TestModels m = new TestModels { Money = 3.3m, Name = "Test", IsTrue = true, TestType = 3 };

//            当Money重复的时候怎么办？
            //            ViewBag.Money = 88m;
            ViewBag.Models = new TestModels { Money = 56m };
            var viewData = ViewData;

            ViewBag.Money = 322m;
            return View(m);
        }

        [ChildActionOnly]
        public ActionResult Menu(string str1="aaa",string str2="bbb")
        {
            List<string> lstMenu = new List<string> {str1, str2, "ccc"};
            return PartialView(lstMenu);
        }

        [HttpPost]
        public ActionResult Test(TestModels t)
        {
            var info = ModelState.IsValid;
            //测试ValidationMessageFor方法。将服务器端的错误返回去。
            ModelState.AddModelError("Name", "Name is too long!!!");
            ModelState.AddModelError("Money", "Invalid");
            ModelState.AddModelError("", "what!!!");
            var info2 = ModelState.IsValid;
            return View(t);
        }

        public ActionResult Message()
        {
            ViewBag.Message = "这是一个子页面";
            return PartialView();
        }
    }
}
